

class Student {
    public String name;
    public int score;
    public void display() {
        System.out.println(name+"考了"+score);
    }
}

class Person {
    public String name;//姓名 成员变量
    public int age;//年龄

    public void eat() {
        System.out.println(name+"正在吃饭");
    }
    public void show() {
        System.out.println("姓名："+name+" 年龄："+age);
    }
}

public class Java9 {
    public static void main5(String[] args) {
        //一个引用能不能指向多个对象？？不能！
        Person person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = new Person();
        person1 = new Person();//保存了最后一个对象
    }

    public static void main4(String[] args) {
        //引用能不能指向引用  不能！！这个说法是不对的
        Person person1 = new Person();
        Person person2 = new Person();
        //这个代表person1这个引用指向了person2这个引用指向的对象
        person1 = person2;
    }

    public static void main3(String[] args) {
        //代表person1不指向任何对象
        Person person1 = null;//不能赋值 空指针异常
        person1.name = "张三";
        person1.age = 10;
    }

    public static void main2(String[] args) {
        //     引用变量
        Person person1 = new Person();//引用指向对象
        person1.name = "张三";
        person1.age = 10;
        System.out.println(person1.name);//默认为null
        System.out.println(person1.age);//默认为0
        person1.show();
        System.out.println("=================");

        Person person2 = new Person();
        person2.name = "lisi";
        person2.age = 20;
        person2.show();
    }

    public static void mai1(String[] args) {
        Student student = new Student();
        student.name = "周星星";
        student.score = 99;
        student.display();
    }
}
